package com.yiwei.zhh.api.requestInfo;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.ContractBean;
import com.yiwei.zhh.api.callback.AboutContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class AboutRequest extends BaseRequest<AboutContract.View> implements AboutContract.Presenter<AboutContract.View> {

    public static AboutRequest create() {
        return new AboutRequest();
    }

    @Override
    public void getAbout() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        Api.api_service.getAboutInfo().compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getAboutSuccess(result);
                });
    }

    @Override
    public void getContractInfo(String id, String type_id, String deal_id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        ContractBean bean = new ContractBean();
        bean.deal_id = deal_id;
        bean.id = id;
        bean.type_id = type_id;

        Api.api_service.getContract(bean).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    mView.complete();
                }).
                subscribe(result -> {
                    mView.getContractSuccess(result);
                });
    }

    @Override
    public void getWeiTuo(String id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        ContractBean bean = new ContractBean();
        bean.id = id;

        Api.api_service.getContract(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    mView.complete();
                }).
                subscribe(result -> {
                    mView.getWeiTuo(result);
                });
    }

    @Override
    public void getFuWuHeTong(String id, String borrow_amount, String borrow_limit_day, String borrow_apr, String service_fee, String bankcard_id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        ContractBean bean = new ContractBean();
        bean.id = id;
        bean.borrow_amount = borrow_amount;
        bean.borrow_apr = borrow_apr;
        bean.borrow_limit_day = borrow_limit_day;
        bean.service_fee = service_fee;
        bean.bankcard_id = bankcard_id;
        Api.api_service.getContract(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    mView.complete();
                }).
                subscribe(result -> {
                    mView.getWeiTuo(result);
                });
    }


}
